<?php
/**
 * 菜品分类管理
 * @author hushuai
 *
 */
class DishSortAction extends CommonAction {
    
    /**
     * 菜品分类管理
     */
    public function index(){
    	
    	if(IS_AJAX){
    			
    		$desc    = $this->_get("orderDirection","trim","desc");;
			$order   = $this->_get("orderName","trim","addtime");
			$pageNum = $this->_get("pageNum","intval",C('PAGE_NUMS'));
			$nowPage = $this->_get("p","intval",1);
			$where   = $this->_get("where","trim","");
				
			$map   = array("where"=>$where,"pageNum"=>$pageNum, "p"=>$nowPage, "orderDirection"=>$desc ,"orderName"=>$order);
			$json  = sendRest("RMS/DishSort/index",$map);
			$data  = $json['data'];
			$count = $data['count'];
				
			$totalPage = ceil($count/$pageNum);
			$jsonData  = array('page'=>$nowPage,'total'=>$count,'totalPage'=>$totalPage);
				
			foreach($data['list'] AS $row){
				$entry = array('id'=>$row['id'],
						'cell'=>array(
								'id'           => $row['id'],
								'title'        => $row['title'],
								'entitle'      => $row['entitle'],
								'addtime'      => date('Y-m-d',$row['addtime']),
						),
				);
				$jsonData['rows'][] = $entry;
			}
				
			$this->ajaxReturn($jsonData,"JSON");
    	}else{
    			
    		$this->display();
    	}
    }
    /**
     * 添加菜品分类
     */
    public function add(){
    	
    	if(IS_AJAX){
			
			$json = sendRest("RMS/DishSort/add",$_POST);
			$this->ajaxReturn($json);
			
    	}else{
    		
    		$jsons = sendRest("RMS/DishSort/view");
    		$this->assign("list",$jsons['data']);
    		$this->display();
    	}
    	
    	
    }
    /**
     * 修改菜品分类
     */
    public function edit(){
    	
    	if(IS_AJAX){
    			
    		$json = sendRest("RMS/DishSort/edit",$_POST);
    		$this->ajaxReturn($json);
    			
    	}else{
   			
    		$map['id']  = $this->_param("id","intval",0);
    		$json       = sendRest("RMS/DishSort/find",$map);
    		
    		if($json['data']['pid']){
    			$maps['id'] = $json['data']['pid'];
    			$title      = sendRest("RMS/DishSort/find",$maps);
    			$this->assign("title",  $title['data']);
    		}else{
    			$this->assign("title", 0);
    		}
    		
    		$this->assign("detail", $json['data']);
    		
    		
    		$this->display();
    	}
    }
    /**
     * 删除菜品分类
     */
    public function del(){
    	
   		if(IS_AJAX){
				
			$map['id'] = $this->_get("id","intval",0);
			$json = sendRest("RMS/DishSort/del",$map);
				
			$this->ajaxReturn($json);
		}
    }
    
    
    /**
     * 酒水列表
     */
    public function drink(){
    
    }
    
    /**
     * 添加酒水
     */
    public function drinkAdd(){
    
    }
    
    /**
     * 修改酒水
     */
    public function drinkEdit(){
    
    }
    
    /**
     * 删除酒水
     */
    public function drinkDel(){
    
    }
}